<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> 

      <el-form-item label="上车地点" prop="pointId">
        <el-select v-model="queryParams.pointid" placeholder="请选择上车地点" clearable>
          <el-option
            v-for="item in pointList"
            :key="item.pointid"
            :label="item.pointname"
            :value="item.pointid"
          />
          </el-select>
      </el-form-item>

      <el-form-item label="车辆类型" prop="typeid">
        <el-select v-model="queryParams.typeid" placeholder="请选择车辆类型" clearable>
          <el-option
            v-for="item in cartypeList"
            :key="item.typeid"
            :label="item.typename"
            :value="item.typeid"
          />
          </el-select>
      </el-form-item>

      <!-- <el-form-item label="结束用车时间" prop="end">
        <el-input
          v-model="queryParams.end"
          placeholder="请输入结束用车时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="用户" prop="userid">
        <el-select v-model="queryParams.userid" placeholder="请选择用户" clearable>
          <el-option
            v-for="item in userList"
            :key="item.userid"
            :label="item.username"
            :value="item.userid"
          />
          </el-select>
      </el-form-item>
      <!-- <el-form-item label="备注" prop="othermsg">
        <el-input
          v-model="queryParams.othermsg"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
      </el-form-item>
      <!-- <el-form-item label="车辆编号" prop="carid">
        <el-input
          v-model="queryParams.carid"
          placeholder="请输入车辆编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
	  
	  <el-form-item label="车辆编号" prop="carid">
	    <el-select v-model="queryParams.carid" placeholder="请输入车辆编号" clearable>
	      <el-option
	        v-for="item in carList"
	        :key="item.carid "
	        :label="item.carname"
	        :value="item.carid"
	      />
	      </el-select>
	  </el-form-item>

      <el-form-item label="订单状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择订单状态" clearable>
          <el-option
            v-for="dict in dict.type.zhsx_orders_types"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <!-- <el-form-item label="${comment}" prop="yl1">
        <el-input
          v-model="queryParams.yl1"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="yl2">
        <el-input
          v-model="queryParams.yl2"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注1" prop="remark1">
        <el-input
          v-model="queryParams.remark1"
          placeholder="请输入备注1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注2" prop="remark2">
        <el-input
          v-model="queryParams.remark2"
          placeholder="请输入备注2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['jypc:carorder:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['jypc:carorder:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['jypc:carorder:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['jypc:carorder:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="carorderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单编号" align="center" prop="orderid" />
      <el-table-column label="上车地点" align="center" prop="point.pointname" />
      <el-table-column label="车辆类型" align="center" prop="cartype.typename" />
      <el-table-column label="用车时间" align="center" prop="start" />
      <el-table-column label="结束用车时间" align="center" prop="end" />
      <el-table-column label="用户" align="center" prop="user.truename" />
      <el-table-column label="车辆" align="center" prop="car.carname" />

      <!-- <el-table-column label="${comment}" align="center" prop="yl1" />
      <el-table-column label="${comment}" align="center" prop="yl2" /> -->

      <el-table-column label="订单审核状态" align="center" prop="status" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zhsx_orders_types" :value="scope.row.status"/>
        </template>
      </el-table-column>

      <!-- <el-table-column label="状态" align="center" prop="status"
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="备注1" align="center" prop="remark1" /> -->
      <!-- <el-table-column label="备注2" align="center" prop="remark2" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['jypc:carorder:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['jypc:carorder:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用车订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!-- <el-form-item label="上车地点编号" prop="pointid">
            <el-input v-model="form.pointid" placeholder="请输入上车地点编号(1或2)" />
          </el-form-item> -->
		  
		 <!-- <el-form-item label="上车地点" prop="pointId" >
		   <el-select v-model="queryParams.pointId" placeholder="请输入上车地点" clearable>
		     <el-option
		       v-for="item in pointList"
		       :key="item.pointid"
		       :label="item.pointname"
		       :value="item.pointid"
		   </el-select>
		 </el-form-item> -->
		 
		 <el-form-item label="上车地点" prop="pointId">
		   <el-select v-model="form.pointid" placeholder="请选择上车地点" clearable>
		     <el-option
		       v-for="item in pointList"
		       :key="item.pointid"
		       :label="item.pointname"
		       :value="item.pointid"
		     />
		     </el-select>
		 </el-form-item>
		  
          <!-- <el-form-item label="车辆类型编号" prop="typeid">
            <el-input v-model="form.typeid" placeholder="请输入车辆类型编号(1或2或3)" />
          </el-form-item> -->
					
						<el-form-item label="车辆类型编号" prop="typeid">
						  <el-select v-model="form.typeid" placeholder="请选择车辆类型" clearable>
							<el-option
							 v-for="item in cartypeList"
							 :key="item.typeid"
							 :label="item.typename"
							 :value="item.typeid"
							/>
							</el-select>
						</el-form-item>
					
          <el-form-item label="开始用车时间" prop="start">
            <el-input v-model="form.start" placeholder="请输入开始用车时间" />
          </el-form-item>
          <el-form-item label="结束用车时间" prop="end">
            <el-input v-model="form.end" placeholder="请输入结束用车时间" />
          </el-form-item>
          <!-- <el-form-item label="用户编号" prop="userid">
            <el-input v-model="form.userid" placeholder="请输入用户编号(1或2或3)" />
          </el-form-item> -->
		  
		  <el-form-item label="用户名称" prop="userid" >
		    <el-select v-model="form.userid" placeholder="请选择用户" clearable>
		      <el-option
		        v-for="item in userList"
		        :key="item.userid"
		        :label="item.username"
		        :value="item.userid"/>
		    </el-select>
		  </el-form-item>
		  
		  
          <el-form-item label="车辆编号" prop="carid">
            <el-input v-model="form.carid" placeholder="请输入车辆编号(1奔驰,2宝马,3大众)" />
          </el-form-item>
		  
		  
		  
          <el-form-item label="订单状态" prop="status">
            <el-radio-group v-model="form.status">
              <el-radio
                v-for="dict in dict.type.zhsx_orders_types"
                :key="dict.value"
                :label="dict.value"
              >{{dict.label}}</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="备注" prop="othermsg">
            <el-input v-model="form.othermsg" placeholder="请输入备注" />
          </el-form-item>

          <!-- <el-form-item label="${comment}" prop="yl1">
            <el-input v-model="form.yl1" placeholder="请输入${comment}" />
          </el-form-item>
          <el-form-item label="${comment}" prop="yl2">
            <el-input v-model="form.yl2" placeholder="请输入${comment}" />
          </el-form-item>
          <el-form-item label="备注1" prop="remark1">
            <el-input v-model="form.remark1" placeholder="请输入备注1" />
          </el-form-item>
          <el-form-item label="备注2" prop="remark2">
            <el-input v-model="form.remark2" placeholder="请输入备注2" />
          </el-form-item> -->
        </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCarorder, getCarorder, delCarorder, addCarorder, updateCarorder } from "@/api/jypc/carorder";
import { listPointAll } from "@/api/jypc/point";
import { listCartypeAll} from "@/api/jypc/cartype";
import {listUserAll} from "@/api/jypc/user.js";
import {listCarAll} from "@/api/jypc/car";
//import { listCarorderpointAll } from

export default {
  name: "Carorder",
  dicts: ['sys_normal_disable','zhsx_carorder_cartype','zhsx_orders_types'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用车订单表格数据
      cartypeList: [],

	carorderList:[],
      //所有上车地点
      pointList:[],

	userList:[],
		//车辆类型查询
		typeList:[],
		
		//车辆编号查询
		carList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pointid: null,
        typeid: null,
        start: null,
        end: null,
        userid: null,
        othermsg: null,
        carid: null,
        yl1: null,
        yl2: null,
        status: null,
        remark1: null,
        remark2: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        pointid: [
          { required: true, message: "上车地点编号不能为空", trigger: "blur" }
        ],
        typeid: [
          { required: true, message: "车辆类型编号不能为空", trigger: "blur" }
        ],
        start: [
          { required: true, message: "开始用车时间不能为空", trigger: "blur" }
        ],
        end: [
          { required: true, message: "结束用车时间不能为空", trigger: "blur" }
        ],
        userid: [
          { required: true, message: "司机编号不能为空", trigger: "blur" }
        ],
        carid: [
          { required: true, message: "车辆编号不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "状态不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
	this.getPointList();
	this.getCartypeList();
	this.getUserList();
	this.getCarList()
  },
  methods: {
    /** 查询用车订单列表 */
    getList() {
      this.loading = true;
      listCarorder(this.queryParams).then(response => {
        this.carorderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // getPointList(){ //查询上车地点列表
	getPointList() {
      listPointAll().then(
      response=>{
      	this.pointList = response.rows;
      });
    },
	getUserList(){  //查询用户信息列表
		listUserAll().then(
		response=>{
			this.userList = response.rows;
		});
	},
	// getPointList(){ //查询上车地点列表
	getCartypeList() {
	  listCartypeAll().then(
	  response=>{
	  	this.cartypeList = response.rows;
	  });
	},
	//查询车辆编号列表
	getcarList(){
		listCarAll().then(
			response=>{
				this.carList = response.rows;
			}
		);
	},
	
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderid: null,
        pointid: null,
        typeid: null,
        start: null,
        end: null,
        userid: null,
        othermsg: null,
        carid: null,
        yl1: null,
        yl2: null,
        status: "0",
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark1: null,
        remark2: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用车订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orderid = row.orderid || this.ids
      getCarorder(orderid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用车订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.orderid != null) {
            updateCarorder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCarorder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderids = row.orderid || this.ids;
      this.$modal.confirm('是否确认删除用车订单编号为"' + orderids + '"的数据项？').then(function() {
        return delCarorder(orderids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('jypc/carorder/export', {
        ...this.queryParams
      }, `carorder_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
